package Interfaz;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import Juego.JuegoServidor;
import Juego.JuegoServidorI;
import ModJuego.JuegoServidorPrx;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class InterfazServidor extends javax.swing.JFrame {
	private JScrollPane jScrollPane1;
	private JButton reinicio;
	private JTextArea jTextArea1;
	private JLabel jLabel1;
	private JButton parar;
	private JButton arrancar;
	private JuegoServidor s;
	private JuegoServidorI juego;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				InterfazServidor inst = new InterfazServidor();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public InterfazServidor() {
		super();
		initGUI();
		s=new JuegoServidor(this);
	}
	
	public void Juego(JuegoServidorI s){
		juego=s;
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			getContentPane().setBackground(new java.awt.Color(217,236,255));
			this.setTitle("Servidor");
			this.setIconImage(new ImageIcon(getClass().getClassLoader().getResource("Imagenes/server.png")).getImage());
			this.setResizable(false);
			{
				jScrollPane1 = new JScrollPane();
				getContentPane().add(jScrollPane1);
				jScrollPane1.setBounds(51, 46, 504, 149);
				{
					jTextArea1 = new JTextArea();
					jScrollPane1.setViewportView(jTextArea1);
					jTextArea1.setEditable(false);
				}
			}
			{
				arrancar = new JButton();
				getContentPane().add(arrancar);
				arrancar.setText("Arrancar");
				arrancar.setBounds(249, 215, 128, 34);
				arrancar.setBackground(new java.awt.Color(255,255,255));
				arrancar.setFont(new java.awt.Font("Segoe UI",1,14));
				arrancar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("Imagenes/arrancar.png")));
				arrancar.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						arrancarMouseClicked(evt);
					}
				});
			}
			{
				parar = new JButton();
				getContentPane().add(parar);
				parar.setVisible(false);
				parar.setText("Parar");
				parar.setBounds(249, 215, 128, 34);
				parar.setBackground(new java.awt.Color(255,255,255));
				parar.setFont(new java.awt.Font("Segoe UI",1,14));
				parar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("Imagenes/parar.png")));
				parar.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						pararMouseClicked(evt);
					}
				});
			}
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("CONSOLA DEL SERVIDOR");
				jLabel1.setBounds(51, 12, 230, 22);
				jLabel1.setForeground(new java.awt.Color(0,0,0));
				jLabel1.setFont(new java.awt.Font("Segoe UI",1,16));
				jLabel1.setBackground(new java.awt.Color(0,0,0));
			}
			{
				reinicio = new JButton();
				getContentPane().add(reinicio);
				reinicio.setText("Reiniciar");
				reinicio.setBounds(48, 216, 107, 29);
				reinicio.setBackground(new java.awt.Color(255,255,255));
				reinicio.setFont(new java.awt.Font("Segoe UI",1,14));
				reinicio.setIcon(new ImageIcon(getClass().getClassLoader().getResource("Imagenes/reinicio.png")));
				reinicio.setSize(128, 34);
				reinicio.setVisible(false);
				reinicio.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						reinicioMouseClicked(evt);
					}
				});
			}
			pack();
			this.setSize(635, 300);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	public void msg(String cadena){
		jTextArea1.append(cadena+"\n");
	}
	
	private void arrancarMouseClicked(MouseEvent evt) {
		s.arrancar();
		arrancar.setVisible(false);
		parar.setVisible(true);
		reinicio.setVisible(true);
	}
	
	private void pararMouseClicked(MouseEvent evt) {
		s.parar();
		jTextArea1.setText("");
		arrancar.setVisible(true);
		parar.setVisible(false);
		reinicio.setVisible(false);
		//dispose();
	} 
	
	private void reinicioMouseClicked(MouseEvent evt) {
		juego.reiniciar();
		
	}

}
